package com.isfto.dao;


import com.github.pagehelper.Page;
import com.isfto.entity.tablepojo.FlightChange;
import com.isfto.entity.tablepojo.UpdateFilghtStatus;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface BeforeFlightChangeEnterAanOutDao {
    /**
     * 进港申请变更之前的数据
     * @param flightChange
     * @return
     */
    @Insert("insert into beforeflightchangeenter(cfno,startapcd,startfptt,endapcd,endfplt,name,email,changereason,flid) " +
            "values(#{cfno},#{startapcd},#{startfptt},#{endapcd},#{endfplt},#{name},#{email},#{changereason},#{flid})")
    int beforeSaveInfo(FlightChange flightChange);

    @Select("select startfptt from beforeflightchangeout where cfno=#{cfno} and flid=#{flid} group by startfptt")
    FlightChange startfptt(@Param("cfno") String cfno,@Param("flid") String flid);

    /**
     * 出港申请变更之前的数据
     * @param flightChange
     * @return
     */
    @Insert("insert into beforeflightchangeout(cfno,startapcd,startfptt,endapcd,endfplt,name,email,changereason,flid) " +
            "values(#{cfno},#{startapcd},#{startfptt},#{endapcd},#{endfplt},#{name},#{email},#{changereason},#{flid})")
    int beforeSaveInfoOut(FlightChange flightChange);

    /**
     * 查看进港申请变更之前的数据
     * @param cfno
     * @param startapcd
     * @param endapcd
     * @return
     */
    @Select("select * from beforeflightchangeenter where cfno=#{cfno} and startapcd=#{startapcd} and endapcd=#{endapcd}")
    List<FlightChange> beforeInfoEnter(@Param("cfno") String cfno,@Param("startapcd") String startapcd,@Param("endapcd") String endapcd);

    /**
     * 查看出港申请变更之前的数据
     * @param cfno
     * @param startapcd
     * @param endapcd
     * @return
     */
    @Select("select * from beforeflightchangeOut where cfno=#{cfno} and startapcd=#{startapcd} and endapcd=#{endapcd}")
    List<FlightChange> beforeInfoOut(@Param("cfno") String cfno,@Param("startapcd") String startapcd,@Param("endapcd") String endapcd);

    /**
     * 删除变更之前重复数据
     * @param cfno
     * @param startapcd
     * @param endapcd
     * @return
     */
    @Delete("delete from beforeflightchangeenter where cfno=#{cfno} and startapcd=#{startapcd} and endapcd=#{endapcd}")
    int deleteInfo(@Param("cfno") String cfno,@Param("startapcd") String startapcd,@Param("endapcd") String endapcd);

    /**
     * 删除变更之后重复数据
     * @param cfno
     * @param startapcd
     * @param endapcd
     * @return
     */
    @Delete("delete from beforeflightchangeout where cfno=#{cfno} and startapcd=#{startapcd} and endapcd=#{endapcd}")
    int  deleteInfoOut(@Param("cfno") String cfno,@Param("startapcd") String startapcd,@Param("endapcd") String endapcd);

    @Select("select flid from flightinfoout1 where fide=#{fide} group by flid")
    String flid(String fide);

    @Select( "select * from flightchangeout where status=#{status};" )
    Page<FlightChange> pageQuery(Integer status);
    @Select( "select * from flightchangeenter where status=#{status};" )
    Page<FlightChange> pageQuery1(Integer status);

    @Update("update flightchangeenter set status=#{status} where fid=#{fid} and cfno = #{cfno}")
    Boolean update(UpdateFilghtStatus updateFilghtStatus);
    @Update("update flightchangeout set status=#{status} where fid=#{fid} and cfno = #{cfno}")
    Boolean update1(UpdateFilghtStatus updateFilghtStatus);
}
